>>>>>>> fb93e06c2e2734954b1f2fc0faf79a30bdd5ce56
type(1)int
2025-02-04
Let’s take a look at the homework
import numpy as np
import os
def AP_check(folder):
AP_sweep_count = 0
for filename in os.listdir(folder):
if filename.endswith('.csv'):
with open(os.path.join(folder, filename), 'r') as file:
data = np.loadtxt(file, skiprows=1)
if any(data > 20):
AP_sweep_count += 1
print("AP found in " + filename)
else:
print('No AP in ' + filename)
return AP_sweep_count
file_path = 'data/sweeps_csv/'
sweep_count = AP_check(file_path)
print(sweep_count)intfloatis instead of ==.is and is not is also checking the type!The important question of what to do “if” something happens.
if something is True
somethingelse
something elsevalue = 3
1if value == 1:
print("the value is 1")
2elif value == 2:
print("the value is 2")
3elif value == 3:
4 print("the value is 3")
else:
print("the value is something else")value is 1
value is 2
value is 3
the value is 3
amplitude = 24
is_action_potential = "is AP" if amplitude > 0 else "no AP"
print(is_action_potential)is AP
Given:
A = [3, 4, 5, 9, 12, 87, -65, 300, 450, -32]
Use for loops to:
1. Add 3 to each element of the list
2. Calculate the average of the list, but negative values are calculated as 0s
3. Find the maximum value
4. Find the index (position) of the max value
# looping through data indices. find the max
B = [1, 4, 6, 7, 89, 54]
big_indx = 0
for i in range(len(B)):
if B[i] > B[big_indx]:
big_indx = i
print('The max value in B is', B[big_indx], 'found on position', big_indx)The max value in B is 89 found on position 4
import numpy as np
array_a = np.arange(20, 25)
for indx, val in enumerate(array_a):
print('the index is', indx)
print('the value is', val)the index is 0
the value is 20
the index is 1
the value is 21
the index is 2
the value is 22
the index is 3
the value is 23
the index is 4
the value is 24
! range() and enumerate() - none of the two returns a list of objects!
while something is TrueThere are useful resources regarding errors